home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BMUG PD-ROM B4
/
PD-ROM B4.iso
/
Entertainment
/
Strategy
/
Robots
/
bot 1.0.1
/
Tutorial
/
ASM
/
Zapper
< prev
next >
Wrap
Text File
|
1991-06-26
|
2KB
|
128 lines
!
! Zapper
!
! This bot recognizes when it takes damage, and it tries to run
! away when it gets hit.
! Its primary weapon is a standard gun. However, it has a
! secondary laser which it fires at the corners of the arena,
! just in case any bots are lurking there.
!
#DATA
EQU INCR 23
DEF DAMAGE
DEF SCAN_AT
DEF XX ! Destination coordinates
DEF YY
DEF GOX ! Prepared velocities for running away
DEF GOY
DEF TEMP
#CODE ASM
JSR CALCPOS ! Pick a point to go to
MUL 20, GOX ! Prepare to accelerate an awful lot
MUL 20, GOY
:INITIALIZE
MOV D0, DAMAGE ! Remember current damage level
:SCANLOOP
CMP D0, DAMAGE ! Have I been hit?
BNE RUNAWAY ! If so, then run away.
ADD INCR, SCAN_AT
:SCANLOCK
SCN SCAN_AT
CMP S0, 0
BEQ SCANLOOP
MOV S1, R1 ! Set angle to target
FIR 1
JMP SCANLOCK
:RAWAY
JSR CALCVEL
MUL 2, GOX ! Move there twice as fast.
MUL 2, GOY
:RUNAWAY
VEL GOX, GOY
MOV XX, TEMP ! Is XX-X0 > 30? Then we're not there
SUB X0, TEMP ! yet. Otherwise, continue on.
CMP TEMP, 30
BGT RAWAY
NEG TEMP, TEMP ! How about X0-XX? If not, loop.
CMP TEMP, 30
BGT RAWAY
MOV YY, TEMP ! YY-Y0 > 30? Same thing.
SUB Y0, TEMP
CMP TEMP, 30
BGT RAWAY
NEG TEMP, TEMP ! Y0-YY? Last one...
CMP TEMP, 30
BGT RAWAY
VEL 0, 0
JSR CALCPOS ! Pick a point to go to
MUL 20, GOX ! Prepare to accelerate an awful lot
MUL 20, GOY
! Before returning to the scan loop, Do a quick zap into the
! four corners of the arena.
CMP A3, 0
BEQ INITIALIZE ! If battery's destroyed
MOV D0, DAMAGE
NEG X0, R8 ! Use scratch registers
NEG Y0, R9
ATN R9, R8 ! Returns the proper angle in R0
MOV R0, R1
FIR 2
CMP D0, DAMAGE
BNE RUNAWAY
ADD 256, R8
ATN R9, R8
MOV R0, R1
FIR 2
CMP D0, DAMAGE
BNE RUNAWAY
ADD 256, R9
ATN R9, R8
MOV R0, R1
FIR 2
CMP D0, DAMAGE
BNE RUNAWAY
NEG X0, R8 ! This is faster than "SUB 256, R8"
ATN R9, R8
MOV R0, R1
FIR 2
CMP D0, DAMAGE
BNE RUNAWAY
JMP INITIALIZE ! Start all over again.
:CALCPOS
RND 215, XX
RND 215, YY
ADD 20, XX
ADD 20, YY
:CALCVEL
MOV XX, GOX
SUB X0, GOX
MOV YY, GOY
SUB Y0, GOY
RET
#END